/**
 * @Description:
 * @Author bianpengfei
 * @create 2021/4/11 13:51
 */
import Vue from 'vue'
import Router from 'vue-router'
import { routerGuard } from './permission'
import routes from './routes'
import { LazyVueRouter } from '@bianpengfei/b-ui/lib/_util/router-cache'
Vue.use(Router)

/* vue-router在在3.0版本以上重复点菜单报错问题*/
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}
const originalReplace = Router.prototype.replace
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch((err) => err)
}

const router = new LazyVueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
routerGuard.call(router)
export default router
